package com.allwees.bs.core.modelbase.transform;

import org.springframework.util.Assert;

import java.util.ArrayList;
import java.util.List;

public abstract class TransformFactoryStrategy {

    protected static List<ObjectTransformFactory<?, ?>> factory = new ArrayList<>();

    public static <F, T> ObjectTransformFactory<F, T> strategy(Class<F> f, Class<T> t) {
        for (ObjectTransformFactory<?, ?> factory : getFactory()) {
            if (factory.match(f, t)) {
                return (ObjectTransformFactory<F, T>) factory;
            }
        }
        Assert.notNull(null, "对象转换错误");
        return null;
    }

    public static List<ObjectTransformFactory<?, ?>> getFactory() {
        return factory;
    }
}
